package com.gxa.community.admin.service.agent.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.community.admin.mapper.agent.UserAgentApplicationDtoMapper;
import com.gxa.community.admin.service.agent.UserAgentApplicationService;
import com.gxa.community.core.pojo.dto.customer.dto.UserAgentApplicationDto;
import com.gxa.community.core.utils.NoUtils;
import com.gxa.community.core.utils.R;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 团长申请表 服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-07-19
 */
@Service
public class UserAgentApplicationServiceImpl extends ServiceImpl<UserAgentApplicationDtoMapper, UserAgentApplicationDto> implements UserAgentApplicationService {

    /**
     * 申请
     * @param userAgentApplicationDto
     * @return
     */
    @Override
    public R addUserApplicationAgent(UserAgentApplicationDto userAgentApplicationDto) {
        //生成用户邀请码
        userAgentApplicationDto.setInviteCode(NoUtils.GenerateInviteCode(userAgentApplicationDto.getUserId().toString()));
        return save(userAgentApplicationDto
                .setIslandAddress(userAgentApplicationDto.getPrecision() + "|" +
                        userAgentApplicationDto.getDimension())) ?
                R.ok("申请成功,等待管理员审核") :
                R.error("申请失败");
    }
}
